<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div id="app">
      <h2>响应式基础</h2>
      <p>count: {{ count }}</p>
      <button v-on:click="fn">btn</button>
      <p>name: {{ name }}</p>
      <ul>
        <li v-for="item in list">{{ item }}</li>
      </ul>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      // 如果希望一个数据有响应式，那么一开始就要给这个数据一个初始值
      // 变量不要用$和_开头
      // methods里面不要使用箭头函数
      const app = createApp({
        data() {
          return {
            count: 1,
            msg: "hello",
            name: undefined,
            list: null,
          };
        },
        methods: {
          fn() {
            this.count++;
          },
          // fn: () => {
          //   this.count++;
          // },
        },
        mounted() {
          console.log(this.count);
          console.log(this.fn);
          setTimeout(() => {
            this.name = "lisi";
            this.list = ["red", "green", "blue"];
          }, 2000);
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
